package arithmetic.leetCode.ds;

/**
 * @author dycong
 * @date 2019/9/14 12:27
 */
public class ListNode {

    public int val;
    public ListNode next;

    public ListNode(int val) {
        this.val = val;
    }


    public static String format(ListNode head) {
        ListNode pre = head;
        StringBuilder builder = new StringBuilder();
        while (pre != null) {
            builder.append(pre.val)
                    .append(",");
            pre = pre.next;
        }
        return builder.toString();
    }


    public static ListNode generate(int length) {
        ListNode head = new ListNode(0);
        ListNode cur = head;
        for (int i = 1; i < length; i++) {
            cur.next = new ListNode(i);
            cur = cur.next;
        }
        return head;
    }
}
